package com.atguigu.admin.interceptors;

import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

// 登录保护拦截器
public class LoginProtectInterceptor implements HandlerInterceptor{
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

        System.err.println("LoginProtectInterceptor.preHandle");
        if(null == request.getSession().getAttribute("userInfo")){
            //重定向到登录页面
            response.sendRedirect(request.getContextPath()+"/index.html");
            return false;
        }else {
            return true;
        }
    }
}
